﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SHDQGSWEB.Models
{
    public class NewsRepository
    {
        SHDQGSDBDataContext db = new SHDQGSDBDataContext();


        public IQueryable<New> FindAllNews()
        {
            return from news in db.News
                   select news;
        }
        public New FindNews(int newId)
        {
            return db.News.Single(n => n.NewId == newId);
        }
        public bool Add(New news)
        {
            try
            {
                db.News.InsertOnSubmit(news);
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
        public bool Delete(New news)
        {
            try
            {
                db.News.DeleteOnSubmit(news);
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
        public bool Save()
        {
            try
            {
                db.SubmitChanges();
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
    }
}